'libtgfx - Threaded Graphics library for FreeBASIC
'Copyright (C) 2013  Ebben Feagan <sir@mud.owlbox.net>
'
'This library is free software; you can redistribute it and/or
'modify it under the terms of the GNU Lesser General Public
'License as published by the Free Software Foundation; either
'version 2.1 of the License, or (at your option) any later version.
'
'This library is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
'Lesser General Public License for more details.
'
'You should have received a copy of the GNU Lesser General Public
'License along with this library; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include once "tgfx.bi"
#include once "tgfx-priv.bi"

namespace tgfx

sub runOnUIThread( byval f as sub( byval as any ptr ), byval ud as any ptr = 0 )
    Comm->send(new Message(_MROUIT, new MData(new sub_data(f,ud),@null_free)))
end sub

constructor sub_data( byval f as sub( byval as any ptr ), byval _x as any ptr )
    d = f
    x = _x
end constructor

constructor Coord() export
    x = 0 : y = 0
end constructor

constructor Coord( byval _x as integer, byval _y as integer ) export
    x = _x
    y = _y
end constructor

constructor init_data( byref p as Coord, byval mo as GFXmode, byval fl as integer )
    d.x = p.x
    d.y = p.y
    m = mo
    f = fl
end constructor



constructor line_data( byval d_ as any ptr, byval f_ as Coord, byval s_ as Coord, byval c_ as uinteger, byval box_ as bool, byval fi_ as bool )
    d = d_
    f = f_
    s = s_
    c = c_
    box = box_
    fill = fi_
end constructor


sub init_d_free( byval x as any ptr )
    var y = cast(init_data ptr, x)
    delete y
end sub

constructor int_data( byval rhs as integer )
    this.d = rhs
end constructor

constructor str_data( byref x as const string, byval x_ as any ptr = 0, byval l_ as Coord = Coord() )
    p = x_
    d = allocate(sizeof(zstring)*(len(x)+1))
    std.memcpy(d,@x[0],len(x))
    d[len(x)] = 0
    l.x = l_.x
    l.y = l_.y
end constructor

sub str_d_free( byval x as any ptr )
    deallocate cast(str_data ptr,x)->d
end sub


sub null_free( byval x as any ptr )
end sub

end namespace
